<template>
  <sui-grid
    :class="grid.columns==3?'three column':'two column'"
    :stackable="grid.re"
    :style="{marginTop:grid.re? -1+'em':-1+'rem'}"
  >
    <sui-grid-row v-for="(row, i) in [1,2]" :key="i">
      <sui-grid-column v-for="(col, j) in [1,2,3]" :key="j">
        <sui-card>
          <sui-card-content :style="{backgroundImage: 'url(' + img + ')',}"></sui-card-content>
          <sui-card-content style="height: 65px;">
            <sui-image :src="`${baseUrl}elliot.jpg`" class="right floated" circular/>
            <sui-card-header style="margin-top: 0.5em;">Elliot Fu</sui-card-header>
            <sui-card-meta>Friends of Veronika</sui-card-meta>
          </sui-card-content>
          <sui-card-content extra style="height: 65px;">
            <ul class="profile profile-stats">
              <li class="profile-card profile-arrange" v-for=" n in 3" :key="n">
                <sui-statistic size="mini">
                  <sui-statistic-label style="margin-bottom:5px">状态</sui-statistic-label>
                  <sui-statistic-value>22</sui-statistic-value>
                </sui-statistic>
              </li>
            </ul>
          </sui-card-content>
        </sui-card>
      </sui-grid-column>
    </sui-grid-row>
  </sui-grid>
</template>
<script>
import resize from "@/mixins/resize";
import { mapActions, mapGetters } from "vuex";
export default {
  name: "card-list",
  mixins: [resize],
  data() {
    return {
      grid: {
        columns: 3,
        re: true,
      },
      baseUrl: process.env.BASE_URL,
      img: require("@/assets/images/elliot.jpg")
    };
  },
  computed: {
    ...mapGetters(["header", "mobileNavigationBar"])
  },
  mounted() {
    this.initResize(this.handler);
    this.handler();
  },
  destroyed() {
    this.destroyResize(this.handler);
    this.handleHeader(true);
    this.handleMoileNavigationBar(true);
  },
  methods: {
    ...mapActions(["handleHeader", "handleMoileNavigationBar"]),
    // 返回当前文档中的<body>元素或者<frameset>元素
    handler() {
      const { body } = document;
      // Document.hidden (只读属性) 返回布尔值,表示页面是(true)否(false)隐藏
      if (!document.hidden) {
        /* Element.getBoundingClientRect() 方法返回元素大小以及对于视口的位置,
         * https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
         */
        let rect = body.getBoundingClientRect();
        /* 判断是否是移动端
         * const WIDTH = 768;
         * 设置比率-const RATIO = 3;
         * let isMobile = rect.width - RATIO < WIDTH;
         */
        let TALBET = 1200;
        let IMOBILE = 600;
        let MOBILE = 768;
        let MODDLE = 900;
        if (rect.width > TALBET) {
          this.grid.columns = 3;
        } else if (rect.width > MODDLE) {
          this.grid.columns = 2;
          this.grid.re = false;
        } else if (rect.width > IMOBILE) {
          this.grid.re = false;
        } else if (rect.width < IMOBILE) {
          this.grid.re = true;
        }

        if (rect.width > MOBILE) {
          if (!this.header.open) {
            this.handleHeader(true);
            this.handleMoileNavigationBar(true);
          }
        } else {
          if (this.header.open) {
            this.handleHeader(false);
            this.handleMoileNavigationBar(false);
          }
        }
        //console.log(rect);
      }
    }
  }
};
</script>
<style lang="less" scoped>
@tablet: 992px;
@mobile: 768px;
.profile {
  box-sizing: border-box;
  display: table;
  margin: 10px 0 0 0;
  min-width: 100%;
  padding: 0;
  table-layout: auto;
}
.profile-stats {
  table-layout: fixed;
}
.profile-card {
  width: 1%;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  line-height: 1;
  overflow: hidden;
  transition: all 0.15s ease-in-out;
}
.profile-arrange {
  vertical-align: bottom;
  display: table-cell;
  padding: 0;
  vertical-align: top;
}
.ui.card,
.ui.cards > .card {
  @media (max-width: 600px) {
    width: 100%;
  }
  border-radius: 0;
  box-shadow: none;
  margin-bottom: 0px;
  cursor: pointer;
  &:active {
    box-shadow: 0 0 0 2px #ffffff, 0 0 2px 4px rgba(152, 28, 235, 0.4);
  }
}
.ui.card > .content,
.ui.cards > .card > .content {
  background-size: 100%;
  height: 95px;
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  background-position: 0 50%;
  width: 100%;
  padding: 0;
  margin-top: -1px;
  border-radius: 0 !important;
}
.ui.right.floated.image,
.ui.right.floated.images {
  background-color: #fff;
  border-radius: 50%;
  margin: -25px 8px 0 0;
  padding: 1px;
  vertical-align: bottom;
  display: inline-block !important;
  max-width: 100%;
  &:active {
    box-shadow: 0 0 0 2px #ffffff, 0 0 2px 4px rgba(152, 28, 235, 0.4);
  }
}
.ui.card .content img,
.ui.cards > .card .content img {
  border-radius: 50%;
  height: 72px;
  width: 72px;
  border: 2px solid #fff;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  color: #fff;
}
</style>
